package com.ruoyi.web.controller.tool;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.SysWorkLine;
import com.ruoyi.system.service.ISysWorkLineService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 产线信息Controller
 * 
 * @author spark
 * @date 2023-07-23
 */
@ApiOperation("产线信息管理")
@RestController
@RequestMapping("/test/line")
@Anonymous
public class TestWorkLineController extends BaseController
{
    @Autowired
    private ISysWorkLineService sysWorkLineService;

    /**
     * 查询产线信息列表
     */
    @ApiOperation("查询产线信息列表")
    @GetMapping("/list")
    public TableDataInfo list(SysWorkLine sysWorkLine)
    {
        startPage();
        List<SysWorkLine> list = sysWorkLineService.selectSysWorkLineList(sysWorkLine);
        return getDataTable(list);
    }

    /**
     * 导出产线信息列表
     */
    @Log(title = "产线信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysWorkLine sysWorkLine)
    {
        List<SysWorkLine> list = sysWorkLineService.selectSysWorkLineList(sysWorkLine);
        ExcelUtil<SysWorkLine> util = new ExcelUtil<SysWorkLine>(SysWorkLine.class);
        util.exportExcel(response, list, "产线信息数据");
    }

    /**
     * 获取产线信息详细信息
     */
    @ApiOperation("获取产线信息详细信息")
    @GetMapping(value = "/{workLineId}")
    public AjaxResult getInfo(@PathVariable("workLineId") Long workLineId)
    {
        return success(sysWorkLineService.selectSysWorkLineByWorkLineId(workLineId));
    }

    /**
     * 新增产线信息
     */
    @ApiOperation("新增产线信息")
    @Log(title = "产线信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysWorkLine sysWorkLine)
    {
        return toAjax(sysWorkLineService.insertSysWorkLine(sysWorkLine));
    }

    /**
     * 修改产线信息
     */
    @ApiOperation("修改产线信息")
    @Log(title = "产线信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysWorkLine sysWorkLine)
    {
        return toAjax(sysWorkLineService.updateSysWorkLine(sysWorkLine));
    }

    /**
     * 删除产线信息
     */
    @ApiOperation("删除产线信息")
    @Log(title = "产线信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{workLineIds}")
    public AjaxResult remove(@PathVariable Long[] workLineIds)
    {
        return toAjax(sysWorkLineService.deleteSysWorkLineByWorkLineIds(workLineIds));
    }
}
